package org.opsli.modulars.system.login.handler.before;

import lombok.extern.slf4j.Slf4j;
import org.opsli.modulars.system.login.dto.LoginModel;
import org.opsli.plugins.Email.EmailCode;
import org.opsli.plugins.security.handler.LoginBeforeListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 浏览器指纹校验 Handler
 */
@Slf4j
@Component
public class LoginModelVerifyFingerprintBeforeHandler implements LoginBeforeListener {
    @Autowired
    EmailCode emailCode;

    @Override
    public Class<?> getModelType() {
        return LoginModel.class;
    }

    @Override
    public void handle(Object model) {
        LoginModel loginModel = (LoginModel) model;
        String fingerprint = loginModel.getFingerprint();
        //校验email验证码
//        if (loginModel.getPrincipal() != null && loginModel.getVerificationCode() != null) {
//            if (emailCode.checkCode(loginModel.getPrincipal(), loginModel.getVerificationCode())) {
//                GuaGuaUtil.set("fingerprint:" + fingerprint, 1, 30, TimeUnit.DAYS);
//                return;
//            } else {
//                throw new ServiceException(400, "Email verification code error");
//            }
//        }
//
//
//        Object obj = GuaGuaUtil.get("fingerprint:" + fingerprint);
//
//        if (fingerprint == null || obj == null) {
//            emailCode.sendCode(loginModel.getPrincipal());
//            throw new ServiceException(400, "Device verification required (code sent to email)");
//        }

        // 可在此处根据cacheInfo.deviceInfo等做更多校验
    }
} 